import requests
class IhrmEmpCURD(object):
    @classmethod
    def add_emp(cls,header,json_data):
        url = "http://ihrm-java.itheima.net/api/sys/user"
        resp = requests.post(url=url,headers=header,json=json_data)
        return resp #添加功能

    @classmethod
    def query_emp(cls,emp_id,header):
        url = "http://ihrm-java.itheima.net/api/sys/user" + emp_id
        resp = requests.get(url=url,headers=header)
        return resp #查询功能

    @classmethod
    def modify_emp(cls,emp_id,header,modify_data):
        url = "http://ihrm-java.itheima.net/api/sys/user" + emp_id
        resp = requests.put(url=url,headers=header,json=modify_data)
        return resp #修改功能6

    @classmethod
    def delete_emp(cls,emp_id,header):
        url = "http://ihrm-java.itheima.net/api/sys/user" + emp_id
        resp = requests.delete(url=url,headers=header)
        return resp #删除功能


if __name__ == '__main__':
    def qinazi():
        url_login = "http://ihrm-java.itheima.net/api/sys/login"  #登录接口
        headers = {
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                          "Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.53"
        }
        data_log = {"mobile":"13800000002","password":"123456"}
        reg = requests.post(url=url_login,headers=headers,json=data_log)
        token_kn = "Bearer "+reg.json()['data']
        print(token_kn)
        return token_kn



# if __name__=="__main__":
#     def qianzhi():
#         import requests  # 版本 2.8
#         #            http://ihrm-java.itheima.net  13800000001  123456
#         url_login = 'http://127.0.0.1:8080/api/sys/login'  # 登录接口
#         json_data = {"mobile": "13800000002", "password": "123456"}  # 登录用户数据
#         res = requests.post(url=url_login, json=json_data)  # 执行脚本
#         token_en = 'Bearer ' + res.json()['data']  # 拼接字符串 ，构造token
#         print(token_en)
#         return token_en
#     json_data = {"username": "业务猪002", "mobile": "18831078891", "workNumber": "10088"}
#     header = {"Content-Type": "application/json", "Authorization": qianzhi()}
#     print(IhrmEmpCURD.add_emp(header=header,json_data=json_data).json())

    header = {"Content-Type": "application/json", "Authorization": qinazi()}
    #添加员工
    #json_data = {"username":"张三","mobile":"13882637878","workNumber":"123456"}
    #print(IhrmEmpCurd.add_emp(header=header,json_data=json_data).json())

    # 查询员工
    #print(IhrmEmpCurd.query_emp(emp_id="1575304188061134848",header=header).json())

    # 修改员工
    #modify_data = {"username":"珊珊","mobile":"13882637888","workNumber":"100000"}
    #print(IhrmEmpCurd.modify_emp(emp_id="1575304188061134848", header=header,modify_data=modify_data).json())

    # 删除员工
    print(IhrmEmpCurd.delete_emp(emp_id="1575304188061134848", header=header).json())